//
//  Ugc_releaseTopic_Tbv_WX.m
//  ZITHER
//
//  Created by weixin on 2019/2/20.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Ugc_releaseTopic_Tbv_WX.h"
#import "Ugc_releasTopic_Cell_WX.h"

@implementation Ugc_releaseTopic_Tbv_WX

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
        [self loadTopiclist];
    }
    return self;
}


-(void)Starefreshing{
    [self loadTopiclist];
}

-(void)loadTopiclist{
    [[serviceDefualt loadTopicSubjectslistPage:self.page reponseObjctClass:[UGC_TopicSubjectslist_model class]]subscribeNext:^(ResponseData* x) {
        if (x.success) {

            [self setNoMoreDataBg:YES NoDataState:NoMoreDataStateDefault];
            
            UGC_TopicSubjectslist_model *model = [UGC_TopicSubjectslist_model yy_modelWithDictionary: x.responseRawData];

            if (model.data.list.count == 0) {
                
                if (self.page == 0 ) {
                    [self setNoMoreDataBg:NO NoDataState:NoMoreDataStateDefault];
                    [Tools showTips:@"暂无更多数据"];
                    [self endRefreshing];
                    [self.mj_footer endRefreshingWithNoMoreData];
                }else{
                    [self.mj_footer endRefreshingWithNoMoreData];
                }
                return ;
            }else{
                if (self.page == 0) {
                    self.model = model;
                }else{
                    for (UGC_TopicSubjectslist_modelList *modelSub in model.data.list) {
                        [self.model.data.list addObject:modelSub];
                    }
                }
            }
            [self endRefreshing];
            [self reloadData];
        }else{
            [Tools showTips:x.errorInfo];
            [self endRefreshing];
        }
    }];
    
}

-(void)defaultConfiguration{
    self.delegate = self;
    self.dataSource = self;
    self.indexSelect = 999;
    self.backgroundColor = [UIColor whiteColor];
    self.clipsToBounds = YES;
    
    

//    self.layer.masksToBounds = YES;
//    self.clipsToBounds = NO;

    
}

#pragma mark -- tabdelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.model.data.list.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self getUgc_releasTopic_Cell_WX:indexPath];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UGC_TopicSubjectslist_modelList *model = self.model.data.list[indexPath.row];
    self.indexSelect = indexPath.row;
    self.hidden = YES;
    if (self.block) {
        self.block(model);
    }
}




-(Ugc_releasTopic_Cell_WX*)getUgc_releasTopic_Cell_WX:(NSIndexPath*)indexPath{
    
    UGC_TopicSubjectslist_modelList *modelSub = self.model.data.list[indexPath.row];
    
    static NSString *sectionCell = @"Ugc_releasTopic_Cell_WX";
    Ugc_releasTopic_Cell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[Ugc_releasTopic_Cell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    
    cell.model = modelSub;
    
    if (self.indexSelect == indexPath.row ) {
        cell.TopicIcon.image = [UIImage imageNamed:@"发布_#话题"];
        cell.TopicLab.textColor = baseColorTheme;
    }else{
        cell.TopicIcon.image = [UIImage imageNamed:@"发布_#话题（未选中）"];
        cell.TopicLab.textColor = HexColor(0x151515);

    }

    return cell;
}



@end
